home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / gnome-menus / examples / gnome-menus-ls.pyc (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  2.4 KB  |  78 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import optparse
  5. import sys
  6. import gmenu
  7.  
  8. def print_entry(entry, path):
  9.     if entry.get_is_excluded():
  10.         excluded = ' <excluded>'
  11.     else:
  12.         excluded = ''
  13.     print '%s\t%s\t%s%s' % (path, entry.get_desktop_file_id(), entry.get_desktop_file_path(), excluded)
  14.  
  15.  
  16. def print_directory(dir, parent_path = None):
  17.     if not parent_path:
  18.         path = '/'
  19.     else:
  20.         path = '%s%s/' % (parent_path, dir.get_name())
  21.     for item in dir.get_contents():
  22.         type = item.get_type()
  23.         if type == gmenu.TYPE_ENTRY:
  24.             print_entry(item, path)
  25.             continue
  26.         if type == gmenu.TYPE_DIRECTORY:
  27.             print_directory(item, path)
  28.             continue
  29.         if type == gmenu.TYPE_ALIAS:
  30.             aliased = item.get_item()
  31.             if aliased.get_type() == gmenu.TYPE_ENTRY:
  32.                 print_entry(aliased, path)
  33.             
  34.         aliased.get_type() == gmenu.TYPE_ENTRY
  35.         if type in [
  36.             gmenu.TYPE_HEADER,
  37.             gmenu.TYPE_SEPARATOR]:
  38.             continue
  39.         print >>sys.stderr, 'Unsupported item type: %s' % type
  40.     
  41.  
  42.  
  43. def main(args):
  44.     parser = optparse.OptionParser()
  45.     parser.add_option('-f', '--file', dest = 'file', help = 'Menu file')
  46.     parser.add_option('-i', '--include-excluded', dest = 'exclude', action = 'store_true', default = False, help = 'Include <Exclude>d entries')
  47.     parser.add_option('-n', '--include-nodisplay', dest = 'nodisplay', action = 'store_true', default = False, help = 'Include NoDisplay=true entries')
  48.     (options, args) = parser.parse_args()
  49.     if options.file:
  50.         menu_file = options.file
  51.     else:
  52.         menu_file = 'applications.menu'
  53.     flags = gmenu.FLAGS_NONE
  54.     if options.exclude:
  55.         flags |= gmenu.FLAGS_INCLUDE_EXCLUDED
  56.     
  57.     if options.nodisplay:
  58.         flags |= gmenu.FLAGS_INCLUDE_NODISPLAY
  59.     
  60.     tree = gmenu.lookup_tree(menu_file, flags)
  61.     root = tree.get_root_directory()
  62.     if not root:
  63.         print 'Menu tree is empty'
  64.     else:
  65.         print_directory(root)
  66.  
  67. if __name__ == '__main__':
  68.     
  69.     try:
  70.         main(sys.argv)
  71.     except KeyboardInterrupt:
  72.         pass
  73.     except:
  74.         None<EXCEPTION MATCH>KeyboardInterrupt
  75.     
  76.  
  77. None<EXCEPTION MATCH>KeyboardInterrupt
  78.